package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.feign.search.SearchFeignClient;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchRespVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;

@Api(tags = "远程调用-商品检索es")
@Controller
public class SearchController {

    @Autowired
    SearchFeignClient searchFeignClient;

    @GetMapping("/list.html")
    public String search (SearchParamVo searchParamVo, Model model){

        //todo 远程调用商品检索 web-all ==> feign-clients ==> service-search
        SearchRespVo searchRespVo = searchFeignClient.search(searchParamVo).getData();

        //1检索的所有参数
        model.addAttribute("searchParam", searchRespVo.getSearchParam());
        //2品牌搜索的面包屑
        model.addAttribute("trademarkParam", searchRespVo.getTrademarkParam());
        //3平台属性面包屑  Props【attrId，attrName，attrValue】
        model.addAttribute("propsParamList", searchRespVo.getPropsParamList());
        //4品牌列表  Trademark【tmId，tmName，tmLogoUrl】
        model.addAttribute("trademarkList", searchRespVo.getTrademarkList());
        //5属性列表  Attrs【attrName，attrId，attrValueList】
        model.addAttribute("attrsList", searchRespVo.getAttrsList());
        //6url参数
        model.addAttribute("urlParam", searchRespVo.getUrlParam());
        //7排序  OrderMap【sort，type】
        model.addAttribute("orderMap", searchRespVo.getOrderMap());
        //8商品集合  Goods【】
        model.addAttribute("goodsList", searchRespVo.getGoodsList());
        //9页码
        model.addAttribute("pageNo", searchRespVo.getPageNo());
        //10总页码
        model.addAttribute("totalPages", searchRespVo.getTotalPages());

        return "list/index";//跳转到此页面
    }
}
